<template>
  <div class="feedback-container">
    <div class="hero-section">
      <div class="hero-content">
        <p class="hero-subtitle">用户反馈</p>
        <h1 class="hero-title">快速反馈，联系我们</h1>
      </div>
    </div>

    <div class="feedback-content">
      <div class="feedback-form">
        <div class="form-header">
          <h2>填写你的反馈信息</h2>
          <p>我们重视您的每一条建议</p>
        </div>
        
        <el-form 
          :rules="rules" 
          ref="fbForm" 
          :model="formMsg"
          label-position="top"
          class="custom-form"
        >
          <div class="form-row">
            <el-form-item label="姓名" prop="name" class="form-item">
              <el-input 
                v-model="formMsg.name" 
                placeholder="请输入您的姓名"
                prefix-icon="el-icon-user"
              ></el-input>
            </el-form-item>
            
            <el-form-item label="电子邮箱" prop="email" class="form-item">
              <el-input 
                v-model="formMsg.email" 
                placeholder="请输入您的邮箱"
                prefix-icon="el-icon-message"
              ></el-input>
            </el-form-item>
          </div>
          
          <el-form-item label="标题" prop="title" class="form-item">
            <el-input 
              v-model="formMsg.title" 
              placeholder="请输入反馈标题"
              prefix-icon="el-icon-edit-outline"
            ></el-input>
          </el-form-item>
          
          <el-form-item label="内容" prop="content" class="form-item">
            <el-input 
              type="textarea" 
              v-model="formMsg.content" 
              :rows="6" 
              placeholder="请详细描述您的反馈内容"
              resize="none"
            ></el-input>
          </el-form-item>
          
          <div class="form-actions">
            <el-button 
              type="primary" 
              @click="submitForm" 
              class="submit-btn"
              :loading="loading"
            >
              <i class="el-icon-send"></i> 提交反馈
            </el-button>
            <el-button @click="resetForm" class="reset-btn">重置</el-button>
          </div>
        </el-form>
      </div>
      
      <div class="contact-info">
        <div class="info-card address-card">
          <div class="card-icon">
            <i class="el-icon-location-outline"></i>
          </div>
          <h3>公司地址位置</h3>
          <p>洛阳市洛龙区科技大道李村街口</p>
        </div>
        
        <div class="info-card contact-card">
          <div class="card-icon">
            <i class="el-icon-message"></i>
          </div>
          <h3>联系我们</h3>
          <p><i class="el-icon-message"></i> contact@abcd.com</p>
          <p><i class="el-icon-phone-outline"></i> 400-123-789456</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Feedback',
  data() {
    return {
      loading: false,
      formMsg: {
        name: this.$store.getters.getUserInfo?.name || '',
        email: this.$store.getters.getUserInfo?.email || '',
        title: '',
        content: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
        ],
        title: [
          { required: true, message: '请输入标题', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '请输入内容', trigger: 'blur' },
          { min: 10, message: '内容不能少于10个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async submitForm() {
      const token = localStorage.getItem('mytoken');
      if (!token) {
        this.$message({
          message: '请先登录',
          type: 'warning'
        });
        return;
      }
      
      this.$refs['fbForm'].validate(async (valid) => {
        if (valid) {
          this.loading = true;
          try {
            this.formMsg.id = this.$store.getters.getUserInfo.id;
            const { data: res } = await this.$axios.post('/api/feedback/add', this.formMsg);
            if (res.status == '200') {
              this.$message({
                message: '反馈成功，感谢您的意见！',
                type: 'success',
                duration: 3000
              });
              this.resetForm();
            }
          } catch (error) {
            this.$message.error('提交失败，请稍后重试');
          } finally {
            this.loading = false;
          }
        }
      });
    },
    resetForm() {
      this.$refs['fbForm'].resetFields();
      this.formMsg = {
        name: this.$store.getters.getUserInfo?.name || '',
        email: this.$store.getters.getUserInfo?.email || '',
        title: '',
        content: ''
      };
    }
  }
}
</script>

<style scoped>
/* 基础样式 */
.feedback-container {
  min-height: 100vh;
  background-color: #f8f9fe;
  font-family: 'Helvetica Neue', Arial, sans-serif;
}

/* 顶部横幅 */
.hero-section {
  background-image: url(@/assets/background3.jpg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  text-align: center;
  position: relative;
  margin-bottom: 100px;
}

.hero-section::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
}

.hero-content {
  position: relative;
  z-index: 1;
  padding: 0 20px;
  max-width: 1200px;
  width: 100%;
}

.hero-subtitle {
  font-size: 18px;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.hero-title {
  font-size: 2.5rem;
  font-weight: 600;
  margin: 0;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
}

/* 主要内容区 */
.feedback-content {
  max-width: 1200px;
  margin: -50px auto 50px;
  padding: 0 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 30px;
}

.feedback-form {
  flex: 1;
  min-width: 300px;
  background: white;
  border-radius: 8px;
  padding: 30px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.form-header {
  margin-bottom: 30px;
}

.form-header h2 {
  font-size: 1.5rem;
  color: #333;
  margin-bottom: 10px;
}

.form-header p {
  color: #666;
  font-size: 0.9rem;
}

.custom-form {
  margin-top: 20px;
}

.form-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.form-item {
  flex: 1;
  min-width: 250px;
}

.form-actions {
  display: flex;
  gap: 15px;
  margin-top: 20px;
}

.submit-btn {
  background: linear-gradient(135deg, #7586fb, #4b6cfb);
  border: none;
  padding: 12px 24px;
  font-weight: 500;
}

.reset-btn {
  padding: 12px 24px;
}

/* 联系信息卡片 */
.contact-info {
  width: 350px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.info-card {
  background: white;
  border-radius: 8px;
  padding: 30px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
  text-align: center;
}

.card-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 20px;
  background: #edeffe;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #7586fb;
  font-size: 24px;
}

.info-card h3 {
  font-size: 1.2rem;
  color: #333;
  margin-bottom: 15px;
}

.info-card p {
  color: #666;
  line-height: 1.8;
  margin: 8px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* 响应式设计 */
@media (max-width: 992px) {
  .feedback-content {
    flex-direction: column;
  }
  
  .contact-info {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }
  
  .info-card {
    flex: 1;
    min-width: 250px;
  }
}

@media (max-width: 768px) {
  .hero-title {
    font-size: 2rem;
  }
  
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  
  .form-item {
    width: 100%;
  }
}

@media (max-width: 576px) {
  .hero-section {
    height: 250px;
  }
  
  .hero-title {
    font-size: 1.8rem;
  }
  
  .feedback-form, .info-card {
    padding: 20px;
  }
  
  .contact-info {
    flex-direction: column;
  }
}
</style>